home *** CD-ROM | disk | FTP | other *** search
/ Alles Voor Internet / Tout Pour Internet / alles voor internet.iso / MacInternet™ / Telnet / NCSA / tn3270 2.3d26 source / tn3270 / dialogs.c < prev    next >
Text File  |  1991-05-23  |  55KB  |  2,421 lines

  1. /*
  2.  *  tn3270 for the Macintosh Source Code
  3.  *  Brown University Computing and Information Services
  4.  *  Version 2.3d21, January 17, 1991
  5.  *  Copyright (c) 1988, 1989, 1990, 1991 by Brown University and by
  6.  *  Peter John DiCamillo.
  7.  *
  8.  *  Permission is granted to any individual or institution to use, copy,
  9.  *  or redistribute the binary version of this software and its
  10.  *  documentation provided this notice and the copyright notices are
  11.  *  retained.  Permission is granted to any individual or non-profit
  12.  *  institution to use, copy, modify, or redistribute the source files
  13.  *  of this software provided this notice and the copyright notices are
  14.  *  retained.  This software may not be distributed for profit, either
  15.  *  in original form or in derivative works, nor can the source be
  16.  *  distributed to other than an individual or a non-profit institution.
  17.  *  Any  individual or group interested in seeing and/or using these
  18.  *  source files but who are prevented from doing so by the above
  19.  *  constraints should contact Don Wolfe, Assistants Vice-President for
  20.  *  Computer Systems at Brown University, (401) 863-7250, for possible
  21.  *  software licensing of the source developed at Brown.
  22.  *
  23.  *  Brown University and Peter John DiCamillo make no representations
  24.  *  about the suitability of this software for any purpose.
  25.  *
  26.  *  BROWN UNIVERSITY AND PETER JOHN DICAMILLO GIVE NO WARRANTY, EITHER
  27.  *  EXPRESS OR IMPLIED, FOR THE PROGRAM AND/OR DOCUMENTATION PROVIDED,
  28.  *  INCLUDING, WITHOUT LIMITATION, WARRANTY OF MERCHANTABILITY AND
  29.  *  WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE.
  30.  *
  31.  */
  32.  
  33. #define __SEG__ 3270seg3
  34. #include "maclib.h"
  35. #include <Lists.h>
  36. #include <CType.h>
  37. #include "termdef.h"
  38. #include "globals.h"
  39.  
  40. OSErr getapcr();
  41.  
  42. #define kButtonFrameSize    3    /* button frame's pen size */
  43. #define kButtonFrameInset  -4    /* inset rectangle adjustment around button */
  44.  
  45. extern char macFName[];
  46. extern char macVName[];
  47. extern char showstg;
  48. char xdlg;
  49. DialogPtr xdlgptr;
  50. extern long textsize, pictsize;
  51. extern char tcpinitok;
  52. extern GDHandle bitmap_gdev;
  53. extern char notifyavail;
  54. extern nmrmessage *myNMR[NMRNUM];
  55. extern struct Point sfgpoint;
  56. OSErr notifymsg(unsigned char *);
  57. char sessionhost[256];
  58. char * dlgmapptr;
  59.  
  60. static short fmtmaxrows, fmtmaxcols;
  61.  
  62. aboutdlg()
  63. {
  64. DialogPtr dlgptr;
  65. DialogPeek dStorage;
  66. WindowPtr behind;
  67. unsigned short (*filterProc) ();
  68. short * itemHitPtr;
  69. short itemHit;
  70. Handle version;
  71. short gtype;
  72. Handle gitem;
  73. Rect gbox;
  74. pascal unsigned short DlgFilter();
  75. static unsigned short * DlgFont = (unsigned short *)0xAFA;
  76.  
  77. version = GetResource('GFTM', 0);
  78. dStorage = 0;
  79. behind = (WindowPtr)-1;
  80. *DlgFont = 1;
  81. dlgptr = GetNewDialog(256, dStorage, behind);
  82. ctrwindow(dlgptr);
  83. GetDItem(dlgptr, 3, >ype, &gitem, &gbox);
  84. ptoc(*version);
  85. SetIText(gitem, *version);
  86. ctop(*version);
  87. arrowcursor();
  88. ShowWindow(dlgptr);
  89.  
  90. /* frame the default selection */
  91. framedflt(dlgptr);
  92.  
  93. filterProc = DlgFilter;
  94. itemHitPtr = &itemHit;
  95. ModalDialog(filterProc, itemHitPtr);
  96. if (itemHit == 2) showstg = 1;
  97. DisposDialog(dlgptr);
  98. *DlgFont = 0;
  99. }
  100.  
  101. stginfo()        /* display storage info. */
  102. {
  103. DialogPtr dlgptr;
  104. DialogPeek dStorage;
  105. WindowPtr behind;
  106. unsigned short (*filterProc) ();
  107. short * itemHitPtr;
  108. short itemHit;
  109. short gtype;
  110. Handle gitem;
  111. Rect gbox;
  112. pascal unsigned short DlgFilter();
  113. char msg[120];
  114. GDHandle currGD;
  115. PixMapHandle currPM;
  116. short i, j;
  117. long l;
  118.  
  119. dStorage = 0;
  120. behind = (WindowPtr)-1;
  121. dlgptr = GetNewDialog(270, dStorage, behind);
  122. ctrwindow(dlgptr);
  123.  
  124. /* define info. text */
  125. if (myWindow != 0) {
  126.     if (colormac) {
  127.         currPM = (*bitmap_gdev)->gdPMap;
  128.         i = (*currPM)->pixelSize;
  129.         j = 2 << (i-1);
  130.         sprintf(msg, "pixel depth = %d (%d colors)", i, j);
  131.         }
  132.     else {
  133.         sprintf(msg, "pixel depth = 1 (black & white)");
  134.         }
  135.     }
  136. else {
  137.     if (colormac) {
  138.         currGD = GetMainDevice();
  139.         currPM = (*currGD)->gdPMap;
  140.         i = (*currPM)->pixelSize;
  141.         j = 2 << (i-1);
  142.         sprintf(msg, "pixel depth = %d (%d colors)", i, j);
  143.         }
  144.     else {
  145.         sprintf(msg, "pixel depth = 1 (black & white)");
  146.         }
  147.     }
  148. GetDItem(dlgptr, 2, >ype, &gitem, &gbox);
  149. SetIText(gitem, msg);
  150.  
  151. if (myWindow != 0) {
  152.     i = (textsize+1023) >> 10;
  153.     if (mapptr == 0) {
  154.         sprintf(msg, "no text bitmap (needs %dK)", i); 
  155.         i = 0;
  156.         }
  157.     else sprintf(msg, "text bitmap = %dK", i);
  158.     }
  159. else {
  160.     i = 0;
  161.     sprintf(msg, "no text bitmap (no session)");
  162.     }
  163. GetDItem(dlgptr, 3, >ype, &gitem, &gbox);
  164. SetIText(gitem, msg);
  165.  
  166. if (myWindow != 0) {
  167.     j = (pictsize+1023) >> 10;
  168.     if (pmapptr == 0) {
  169.         sprintf(msg, "no graphics bitmap (needs %dK)", j);
  170.         j = 0;
  171.         }
  172.     else sprintf(msg, "graphics bitmap = %dK", j);
  173.     }
  174. else {
  175.     j = 0;
  176.     sprintf(msg, "no graphics bitmap (no session)");
  177.     }
  178. GetDItem(dlgptr, 4, >ype, &gitem, &gbox);
  179. SetIText(gitem, msg);
  180.  
  181. sprintf(msg, "bitmap total = %dK", i+j);
  182. GetDItem(dlgptr, 5, >ype, &gitem, &gbox);
  183. SetIText(gitem, msg);
  184.  
  185. MaxApplZone();
  186. l = FreeMem() >> 10;
  187. sprintf(msg, "available storage = %ldK", l);
  188. GetDItem(dlgptr, 6, >ype, &gitem, &gbox);
  189. SetIText(gitem, msg);
  190. arrowcursor();
  191. ShowWindow(dlgptr);
  192.  
  193. /* frame the default selection */
  194. framedflt(dlgptr);
  195.  
  196. /* show the text */
  197. filterProc = DlgFilter;
  198. itemHitPtr = &itemHit;
  199. ModalDialog(filterProc, itemHitPtr);
  200. DisposDialog(dlgptr);
  201. }
  202.  
  203. attrdlg()
  204. {
  205. DialogPtr dlgptr;
  206. DialogPeek dStorage;
  207. WindowPtr behind;
  208. unsigned short (*filterProc) ();
  209. short * itemHitPtr;
  210. short itemHit;
  211. short gtype;
  212. Handle gitem;
  213. Rect gbox;
  214. unsigned char tempmap[35];
  215. register short i, j;
  216. register unsigned char c;
  217. pascal unsigned short DlgFilter();
  218.  
  219. dStorage = 0;
  220. behind = (WindowPtr)-1;
  221. dlgptr = GetNewDialog(257, dStorage, behind);
  222. ctrwindow(dlgptr);
  223.  
  224. /* handle attribute selection dialog */
  225. filterProc = DlgFilter;
  226. itemHitPtr = &itemHit;
  227. itemHit = 99;
  228. j = 0;
  229. for (i=0; i<7; i++) {
  230.     c = cs.attrmap[i] >> 3;
  231.     tempmap[j++] = (c & 0x10) >> 4;
  232.     tempmap[j++] = (c & 0x08) >> 3;
  233.     tempmap[j++] = (c & 0x04) >> 2;
  234.     tempmap[j++] = (c & 0x02) >> 1;
  235.     tempmap[j++] = c & 0x01;
  236.     }
  237. for (i=0; i < 35; i++) {
  238.     GetDItem(dlgptr, i+18, >ype, &gitem, &gbox);
  239.     SetCtlValue(gitem, tempmap[i]);
  240.     }
  241. arrowcursor();
  242. ShowWindow(dlgptr);
  243.  
  244. /* frame the default selection */
  245. framedflt(dlgptr);
  246.  
  247. while ((itemHit != 1) && (itemHit != 3)) {
  248.     ModalDialog(filterProc, itemHitPtr);
  249.     if (itemHit == 2) {        /* set defaults */
  250.         j = 0;
  251.         for (i=0; i<7; i++) {
  252.             c = dfltmap[i] >> 3;
  253.             tempmap[j++] = (c & 0x10) >> 4;
  254.             tempmap[j++] = (c & 0x08) >> 3;
  255.             tempmap[j++] = (c & 0x04) >> 2;
  256.             tempmap[j++] = (c & 0x02) >> 1;
  257.             tempmap[j++] = c & 0x01;
  258.             }
  259.         for (i=0; i < 35; i++) {
  260.             GetDItem(dlgptr, i+18, >ype, &gitem, &gbox);
  261.             SetCtlValue(gitem, tempmap[i]);
  262.             }
  263.         }
  264.     else {
  265.         i = itemHit - 18;
  266.         tempmap[i] ^= 1;
  267.         GetDItem(dlgptr, itemHit, >ype, &gitem, &gbox);
  268.         SetCtlValue(gitem, tempmap[i]);
  269.         }
  270.     }
  271.  
  272. if (itemHit == 1) {
  273.     j = 0;
  274.     for (i=0; i<7; i++) {
  275.         c = (tempmap[j]<<4) + (tempmap[j+1]<<3) + (tempmap[j+2]<<2) +
  276.             (tempmap[j+3]<<1) + tempmap[j+4];
  277.         j += 5;
  278.         c <<= 3;
  279.         cs.attrmap[i] = c;
  280.         }
  281.     if (myWindow != 0) invldscr();
  282.     }
  283.  
  284. /* dispose of dialog and return */
  285. DisposDialog(dlgptr);
  286. }
  287.  
  288. commdlg()
  289. {
  290. DialogPtr dlgptr;
  291. DialogPeek dStorage;
  292. WindowPtr behind;
  293. unsigned short (*filterProc) ();
  294. short * itemHitPtr;
  295. short itemHit, oldHit;
  296. short gtype;
  297. Handle gitem;
  298. Rect gbox;
  299. unsigned char s[256];
  300. char d_hostname[128];
  301. char d_setsflg, d_dblevel;
  302. unsigned char d_timeout, d_retries, d_autoconn;
  303. short i;
  304. int r;
  305. pascal unsigned short DlgFilter();
  306.  
  307. dStorage = 0;
  308. behind = (WindowPtr)-1;
  309. if (specuser) i = 258;
  310.     else i = 262;
  311. dlgptr = GetNewDialog(i, dStorage, behind);
  312. ctrwindow(dlgptr);
  313.  
  314. /* copy current values of items */
  315. movmem(cshostname, d_hostname, 128);
  316. d_setsflg = cs.setsflg;
  317. d_dblevel = cs.dblevel;
  318. d_timeout = cs.timeout;
  319. d_retries = cs.retries;
  320. d_autoconn = cs.autoconn;
  321.  
  322. /* show current values of items */
  323. setcomm(dlgptr, d_hostname, d_setsflg, d_timeout, d_retries,
  324.         d_dblevel, d_autoconn);
  325. /* select host name text */
  326. SelIText(dlgptr, 5, 0, 32767);
  327.  
  328. /* Make Default is only for TCP */
  329. if (!tcpflg && !specuser) {
  330.     GetDItem(dlgptr, 6, >ype, &gitem, &gbox);
  331.     HiliteControl(gitem, 255);
  332.     }
  333. arrowcursor();
  334. ShowWindow(dlgptr);
  335.  
  336. /* frame the default selection */
  337. framedflt(dlgptr);
  338.  
  339. /* loop to process changes */
  340.  
  341. filterProc = DlgFilter;
  342. itemHitPtr = &itemHit;
  343. oldHit = 0;
  344. while (1) {
  345.     ModalDialog(filterProc, itemHitPtr);
  346.     if ((oldHit > 0) && (oldHit != itemHit))
  347.         switch(oldHit) {
  348.         case 5:                                    /* hostname */
  349.                 GetDItem(dlgptr, 5, >ype, &gitem, &gbox);
  350.                 GetIText(gitem, s);
  351.                 if (d_setsflg == 2) {
  352.                     if (strlen(s) > 127) s[127] = 0;
  353.                     }
  354.                 else if (strlen(s) > 31) s[31] = 0;
  355.                 i = 0;
  356.                 while (s[i] != 0) {
  357.                     if (d_setsflg == 2) d_hostname[i] = s[i];
  358.                     else d_hostname[i] = toupper(s[i]);
  359.                     i++;
  360.                     }
  361.                 d_hostname[i] = 0;
  362.                 SetIText(gitem, d_hostname);
  363.                 break;
  364.         case 12:                                /* timeout   */
  365.         case 14:                                /* retries   */
  366.         case 16:                                /* debug level */
  367.                 GetDItem(dlgptr, oldHit, >ype, &gitem, &gbox);
  368.                 GetIText(gitem, s);
  369.                 if (sscanf(s, "%d", &r) != 1) r = 0;
  370.                 if (oldHit == 12) {
  371.                     if ((r > 0) && (r <= 10)) d_timeout = r;
  372.                     sprintf(s, "%2d", d_timeout);
  373.                     }
  374.                 else if (oldHit == 14) {
  375.                     if ((r > 0) && (r <= 99)) d_retries = r;
  376.                     sprintf(s, "%2d", d_retries);
  377.                     }
  378.                 else {
  379.                     if ((r >= 0) && (r <= 127)) d_dblevel = r;
  380.                     sprintf(s, "%2d", d_dblevel);
  381.                     }
  382.                 SetIText(gitem, s);
  383.                 break;
  384.         default:
  385.                 break;
  386.         }
  387.     oldHit = itemHit;
  388.     switch(itemHit) {
  389.         case 1:                                    /* OK */
  390.                 movmem(d_hostname, cshostname, 128);
  391.                 cs.setsflg = d_setsflg;
  392.                 cs.dblevel = d_dblevel;        /* copy new settings */
  393.                 cs.timeout = d_timeout;
  394.                 cs.retries = d_retries;
  395.                 cs.autoconn = d_autoconn;
  396.                 break;
  397.         case 2:                                    /* set defaults */
  398.                 d_setsflg = dfltsflg;
  399.                 if (d_setsflg == 2) tcpdflthost(d_hostname);
  400.                 else if (d_setsflg == 1) serdflthost(d_hostname);
  401.                 else netdflthost(d_hostname);
  402.                 d_autoconn = 1;
  403.                 if (specuser) {
  404.                     d_dblevel = 0;
  405.                     d_timeout = 1;
  406.                     d_retries = 15;
  407.                     }
  408.                 setcomm(dlgptr, d_hostname, d_setsflg,
  409.                         d_timeout, d_retries, d_dblevel, d_autoconn);
  410.                 i = strlen(d_hostname);
  411.                 SelIText(dlgptr, 5, i, i);
  412.                 break;
  413.         case 6:                    /* Make Default for host name */
  414.                 GetDItem(dlgptr, 5, >ype, &gitem, &gbox);
  415.                 GetIText(gitem, s);
  416.                 updhostrsc(s);
  417.                 break;
  418.         case 7:                    /* auto-connect check box */
  419.                 d_autoconn ^= 1;
  420.                 setit(7, dlgptr, d_autoconn);
  421.                 break;
  422.         case 8:                                    /* AppleTalk */
  423.         case 9:                                    /* Serial    */
  424.         case 10:                                /* TCP/IP     */
  425.                 d_setsflg = itemHit - 8;
  426.                 GetDItem(dlgptr, 8, >ype, &gitem, &gbox);
  427.                 SetCtlValue(gitem, d_setsflg == 0);
  428.                 GetDItem(dlgptr, 9, >ype, &gitem, &gbox);
  429.                 SetCtlValue(gitem, d_setsflg  == 1);
  430.                 GetDItem(dlgptr, 10, >ype, &gitem, &gbox);
  431.                 SetCtlValue(gitem, d_setsflg  == 2);
  432.                 break;
  433.         default: break;
  434.         }
  435.     if ((itemHit == 1) || (itemHit == 3)) break;
  436.     }
  437.  
  438. /* dispose of dialog and return */
  439. DisposDialog(dlgptr);
  440. }
  441.  
  442. setcomm(dlgptr, hname, sflg, timeout, retries, debug, autoconn)
  443. DialogPtr dlgptr;
  444. char * hname;
  445. char sflg, debug, autoconn;
  446. unsigned char timeout, retries;
  447. {
  448. short gtype;
  449. Handle gitem;
  450. Rect gbox;
  451. char s[40];
  452.  
  453. GetDItem(dlgptr, 5, >ype, &gitem, &gbox);        /* hostname */
  454. SetIText(gitem, hname);
  455.  
  456. setit(7, dlgptr, autoconn);                        /* auto-connect */
  457.  
  458. if (!specuser) return;
  459.  
  460. GetDItem(dlgptr, 8, >ype, &gitem, &gbox);        /* AppleTalk */
  461. SetCtlValue(gitem, sflg == 0);
  462.  
  463. GetDItem(dlgptr, 9, >ype, &gitem, &gbox);        /* Serial */
  464. SetCtlValue(gitem, sflg  == 1);
  465.  
  466. GetDItem(dlgptr, 10, >ype, &gitem, &gbox);    /*  TCP/IP */
  467. SetCtlValue(gitem, sflg  == 2);
  468.  
  469. GetDItem(dlgptr, 12, >ype, &gitem, &gbox);    /* timeout */
  470. sprintf(s, "%2d", timeout);
  471. SetIText(gitem, s);
  472.  
  473. GetDItem(dlgptr, 14, >ype, &gitem, &gbox);    /* retries */
  474. sprintf(s, "%2d", retries);
  475. SetIText(gitem, s);
  476.  
  477. GetDItem(dlgptr, 16, >ype, &gitem, &gbox);    /* debug level */
  478. sprintf(s, "%2d", debug);
  479. SetIText(gitem, s);
  480. }
  481.  
  482. OSErr hostdlg(s)
  483. unsigned char *s;    /* "s" assumed to be 128 bytes */
  484. {
  485. DialogPtr dlgptr;
  486. DialogPeek dStorage;
  487. WindowPtr behind;
  488. unsigned short (*filterProc) ();
  489. short itemHit, oldHit;
  490. short gtype;
  491. Handle gitem;
  492. Rect gbox;
  493. unsigned char d_hostname[256];
  494. OSErr rc;
  495. pascal unsigned short DlgFilter();
  496.  
  497. dStorage = 0;
  498. behind = (WindowPtr)-1;
  499. dlgptr = GetNewDialog(282, dStorage, behind);
  500. ctrwindow(dlgptr);
  501.  
  502. /* copy current values of items */
  503. movmem(s, d_hostname, 256);
  504.  
  505. /* define host name text */
  506. GetDItem(dlgptr, 4, >ype, &gitem, &gbox);        /* hostname */
  507. SetIText(gitem, d_hostname);
  508. SelIText(dlgptr, 4, 0, 32767);
  509. arrowcursor();
  510. ShowWindow(dlgptr);
  511.  
  512. /* frame the default selection */
  513. framedflt(dlgptr);
  514.  
  515. /* loop to process changes */
  516.  
  517. filterProc = DlgFilter;
  518. oldHit = 0;
  519. rc = 1;            /* assume "cancel" */
  520. while (1) {
  521.     ModalDialog(filterProc, &itemHit);
  522.     if ((oldHit > 0) && (oldHit != itemHit))
  523.         switch(oldHit) {
  524.         case 4:                                    /* hostname */
  525.                 GetDItem(dlgptr, 4, >ype, &gitem, &gbox);
  526.                 GetIText(gitem, d_hostname);
  527.                 if (strlen(d_hostname) > 127) {
  528.                     d_hostname[127] = 0;
  529.                     }
  530.                 SetIText(gitem, d_hostname);
  531.                 break;
  532.         default:
  533.                 break;
  534.         }
  535.     oldHit = itemHit;
  536.     switch(itemHit) {
  537.         case 1:                                    /* OK */
  538.                 strcpy(s, d_hostname);
  539.                 rc = 0;
  540.                 break;
  541.         default: break;
  542.         }
  543.     if ((itemHit == 1) || (itemHit == 2)) break;
  544.     }
  545.  
  546. /* dispose of dialog and return */
  547. DisposDialog(dlgptr);
  548. return(rc);
  549. }
  550.  
  551. featdlg()
  552. {
  553. DialogPtr dlgptr;
  554. DialogPeek dStorage;
  555. WindowPtr behind;
  556. unsigned short (*filterProc) ();
  557. short itemHit;
  558. char d_insreset, d_impnull, d_repnull, d_digitpfk, d_ext3270, d_std_brack;
  559. pascal unsigned short DlgFilter();
  560. static char * ScrDmpEnb = (char *)0x2f8;
  561.  
  562. dStorage = 0;
  563. behind = (WindowPtr)-1;
  564. dlgptr = GetNewDialog(260, dStorage, behind);
  565. ctrwindow(dlgptr);
  566.  
  567. /* copy current values of items */
  568. d_insreset = cs.insreset;
  569. d_impnull = cs.impnull;
  570. d_repnull = cs.repnull;
  571. d_digitpfk = cs.digitpfk;
  572. d_ext3270 = cs.ext3270;
  573. d_std_brack = cs.std_brack;
  574.  
  575. /* show current values of items */
  576. setfeat(dlgptr, d_insreset, d_impnull, d_repnull, d_digitpfk, d_ext3270,
  577.         d_std_brack);
  578. arrowcursor(); 
  579. ShowWindow(dlgptr);
  580.  
  581. /* frame the default selection */
  582. framedflt(dlgptr);
  583.  
  584. /* loop to process changes */
  585.  
  586. filterProc = DlgFilter;
  587. while (1) {
  588.     ModalDialog(filterProc, &itemHit);
  589.     switch(itemHit) {
  590.         case 1:                                    /* OK */
  591.                 cs.insreset = d_insreset;
  592.                 cs.impnull = d_impnull;
  593.                 cs.repnull = d_repnull;
  594.                 cs.digitpfk = d_digitpfk;
  595.                 cs.ext3270 = d_ext3270;
  596.                 cs.std_brack = d_std_brack;
  597.                 fixbracket = cs.std_brack && (!aplmode) && (stdfont != ALAFONT);
  598.                 if (cs.digitpfk) (*ScrDmpEnb) = 0;
  599.                         else  (*ScrDmpEnb) = ScrDmpSav;
  600.                 break;
  601.         case 3:                                    /* yes */
  602.         case 4:                                    /* no */
  603.                 d_insreset = 4 - itemHit;
  604.                 setfeat(dlgptr, d_insreset, d_impnull, d_repnull, d_digitpfk,
  605.                         d_ext3270, d_std_brack);
  606.                 break;
  607.         case 6:                                    /* yes */
  608.         case 7:                                    /* no */
  609.                 d_impnull = 7 - itemHit;
  610.                 setfeat(dlgptr, d_insreset, d_impnull, d_repnull, d_digitpfk,
  611.                         d_ext3270, d_std_brack);
  612.                 break;
  613.         case 9:                                    /* yes */
  614.         case 10:                                /* no */
  615.                 d_repnull = 10 - itemHit;
  616.                 setfeat(dlgptr, d_insreset, d_impnull, d_repnull, d_digitpfk,
  617.                         d_ext3270, d_std_brack);
  618.                 break;
  619.         case 12:                                /* yes */
  620.         case 13:                                /* no */
  621.                 d_digitpfk = 13 - itemHit;
  622.                 setfeat(dlgptr, d_insreset, d_impnull, d_repnull, d_digitpfk,
  623.                         d_ext3270, d_std_brack);
  624.                 break;
  625.         case 15:                                /* yes */
  626.         case 16:                                /* no */
  627.                 d_ext3270 = 16 - itemHit;
  628.                 setfeat(dlgptr, d_insreset, d_impnull, d_repnull, d_digitpfk,
  629.                         d_ext3270, d_std_brack);
  630.                 break;
  631.         case 18:                                /* yes */
  632.         case 19:                                /* no */
  633.                 d_std_brack = 19 - itemHit;
  634.                 setfeat(dlgptr, d_insreset, d_impnull, d_repnull, d_digitpfk,
  635.                         d_ext3270, d_std_brack);
  636.                 break;
  637.         case 20:                            /* set defaults */
  638.                 d_insreset = d_impnull = d_repnull = d_digitpfk = d_ext3270 = 
  639.                     d_std_brack = 1;
  640.                 setfeat(dlgptr, d_insreset, d_impnull, d_repnull, d_digitpfk,
  641.                         d_ext3270, d_std_brack);
  642.                 break;
  643.  
  644.         default: break;
  645.         }
  646.     if ((itemHit == 1) || (itemHit == 21)) break;
  647.     }
  648.  
  649. /* dispose of dialog and return */
  650. DisposDialog(dlgptr);
  651. }
  652.  
  653. setfeat(dlgptr, d_insreset, d_impnull, d_repnull, d_digitpfk, d_ext3270, 
  654.     d_std_brack)
  655. DialogPtr dlgptr;
  656. char d_insreset, d_impnull, d_repnull, d_digitpfk, d_ext3270, d_std_brack;
  657. {
  658. setit(3, dlgptr, d_insreset != 0);                /* yes */
  659. setit(4, dlgptr, d_insreset == 0);                /* no */
  660.  
  661. setit(6, dlgptr, d_impnull != 0);                /* yes */
  662. setit(7, dlgptr, d_impnull == 0);                /* no */
  663.  
  664. setit(9, dlgptr, d_repnull != 0);                /* yes */
  665. setit(10, dlgptr, d_repnull == 0);                /* no */
  666.  
  667. setit(12, dlgptr, d_digitpfk != 0);                /* yes */
  668. setit(13, dlgptr, d_digitpfk == 0);                /* no */
  669.  
  670. setit(15, dlgptr, d_ext3270 != 0);                /* yes */
  671. setit(16, dlgptr, d_ext3270 == 0);                /* no */
  672.  
  673. setit(18, dlgptr, d_std_brack != 0);            /* yes */
  674. setit(19, dlgptr, d_std_brack == 0);            /* no */
  675. }
  676.  
  677. savedlg()
  678. {
  679. DialogPtr dlgptr;
  680. DialogPeek dStorage;
  681. WindowPtr behind;
  682. unsigned short (*filterProc) ();
  683. short * itemHitPtr;
  684. short itemHit;
  685. pascal unsigned short DlgFilter();
  686.  
  687. dStorage = 0;
  688. behind = (WindowPtr)-1;
  689. dlgptr = GetNewDialog(261, dStorage, behind);
  690. ctrwindow(dlgptr);
  691. arrowcursor();
  692. ShowWindow(dlgptr);
  693.  
  694. /* frame the default selection */
  695. framedflt(dlgptr);
  696.  
  697. /* loop to process changes */
  698.  
  699. filterProc = DlgFilter;
  700. itemHitPtr = &itemHit;
  701. while (1) {
  702.     ModalDialog(filterProc, itemHitPtr);
  703.     if (itemHit == 1) break;
  704.     if (itemHit == 2) break;
  705.     }
  706. /* dispose of dialog and return */
  707. DisposDialog(dlgptr);
  708. return(2 - itemHit);
  709. }
  710.  
  711. clickdlg()
  712. {
  713. DialogPtr dlgptr;
  714. DialogPeek dStorage;
  715. WindowPtr behind;
  716. unsigned short (*filterProc) ();
  717. short gtype;
  718. Handle gitem;
  719. Rect gbox, mybox;
  720. void (*myitem) ();
  721. short itemHit;
  722. short * itemHitPtr;
  723. short savepf, temppf;
  724. GrafPtr gp;
  725. pascal unsigned short DlgFilter();
  726. pascal void attndlg();
  727. pascal void attnmenu(short, MenuHandle,
  728.     Rect *, Point, short *);
  729. /* long lpoint; */
  730.  
  731. dStorage = 0;
  732. behind = (WindowPtr)-1;
  733. dlgptr = GetNewDialog(266, dStorage, behind);
  734. ctrwindow(dlgptr);
  735.  
  736. /* define routine to draw user item */
  737. GetDItem(dlgptr, 4, >ype, &gitem, &mybox);
  738. myitem = attndlg;
  739. SetDItem(dlgptr, 4, gtype, myitem, &mybox);
  740. arrowcursor();
  741. ShowWindow(dlgptr);
  742.  
  743. /* frame the default selection */
  744. framedflt(dlgptr);
  745.  
  746. itemHit = 99;
  747. itemHitPtr = &itemHit;
  748. filterProc = DlgFilter;
  749. savepf = cs.mousepf;
  750. while ((itemHit != 1) && (itemHit != 3)) {
  751.     ModalDialog(filterProc, itemHitPtr);
  752.     switch(itemHit) {
  753.         case 1:                /* OK */
  754.                 break;
  755.         case 2:                /* Set Default */
  756.                 mousehit.v = mybox.top + 85;
  757.                 mousehit.h = mybox.left + 279;
  758.                 GetPort(&gp);
  759.                 SetPort(dlgptr);
  760.                 LocalToGlobal(&mousehit);
  761.                 SetPort(gp);
  762.         case 4:                /* Function Keys */
  763.                 GetPort(&gp);
  764.                 SetPort(dlgptr);
  765.                 GlobalToLocal(&mousehit);
  766.                 /* movmem(&mousehit, &lpoint, 4);     struct -> long */
  767.                 temppf = cs.mousepf;
  768.                 attnmenu(mChooseMsg, (MenuHandle)0, &mybox,
  769.                             mousehit, &cs.mousepf);
  770.                 if (cs.mousepf == 0) {
  771.                     cs.mousepf = temppf;
  772.                     attnmenu(mChooseMsg, (MenuHandle)0, &mybox,
  773.                                 mousehit, &cs.mousepf);
  774.                     cs.mousepf = temppf;
  775.                     }
  776.                 SetPort(gp);
  777.                 break;
  778.         case 3:                /* Cancel */
  779.                 cs.mousepf = savepf;
  780.                 break;
  781.         default:
  782.                 break;
  783.         }
  784.     }
  785. DisposDialog(dlgptr);
  786. }
  787.  
  788. stgalert(kind, routine, amount)
  789. char * kind;
  790. char * routine;
  791. long amount;
  792. {
  793. char message[80];
  794. pascal unsigned short DlgFilter();
  795. unsigned short (*filterProc) ();
  796.  
  797. filterProc = DlgFilter;
  798. sprintf(message, "%s attempt to allocate %ld bytes for %s failed.",
  799.         routine, amount, kind);
  800. dbdlg(message);
  801. StopAlert(263, filterProc);
  802. }
  803.  
  804. /* code taken from dbprint */
  805. dbdlg(string)
  806. char *string;
  807. {
  808.    DialogRecord dStorage;
  809.    Rect boundry;
  810.    char visible = 0, goAway = 0;
  811.    WindowPtr behind = (WindowPtr)-1;
  812.    struct {
  813.       short numitems;
  814.       /* Button stuff */
  815.       long Bhandle;
  816.       short Btop,
  817.             Bleft,
  818.             Bbottom,
  819.             Bright;
  820.       char Btype;
  821.       char Blen;
  822.       char Btext[2];
  823.       /* Text item */
  824.       long Thandle;
  825.       short Ttop,
  826.             Tleft,
  827.             Tbottom,
  828.             Tright;
  829.       char Ttype;
  830.       char Tlen;
  831.       char Ttext[255];
  832.       } DStruct;
  833.    DialogPtr theBox;
  834.    short dummy, l;
  835.    Size DSsize;
  836.    Handle itemlist;
  837.    pascal unsigned short DlgFilter();
  838.    unsigned short (*filterProc) ();
  839.    OSErr rc;
  840.  
  841.    if (cs.dblevel == 0) return;
  842.  
  843.    if (mf_bgrnd && notifyavail) {
  844.         c2pstr(string);
  845.         rc = notifymsg(string);
  846.         p2cstr(string);
  847.         if (rc == noErr) return;
  848.         }
  849.  
  850.    filterProc = DlgFilter;
  851.  
  852.    DStruct.numitems = 1;
  853.    DStruct.Thandle =  0;
  854.    DStruct.Ttop = 50;
  855.    DStruct.Tleft = 30;
  856.    DStruct.Tbottom = 100;
  857.    DStruct.Tright = 260;
  858.    DStruct.Ttype =    statText + itemDisable;
  859.    l = strlen(string);
  860.    if (l > 254) l = 254;
  861.    strcpy(DStruct.Ttext, string);
  862.    if (l%2) {
  863.        strcat(DStruct.Ttext, " ");
  864.        l++;
  865.        }
  866.    DStruct.Tlen = l;
  867.    DStruct.Bhandle = 0;
  868.    DStruct.Btop = 10;
  869.    DStruct.Bleft = 160;
  870.    DStruct.Bbottom = 30;
  871.    DStruct.Bright = 240;
  872.    DStruct.Btype = ctrlItem + btnCtrl;
  873.    DStruct.Blen = 2;
  874.    DStruct.Btext[0] = 'O';
  875.    DStruct.Btext[1] = 'K';
  876.  
  877.    boundry.top = 120;
  878.    boundry.left = 120;
  879.    boundry.bottom = 240;
  880.    boundry.right = 400;
  881.  
  882.    DSsize = sizeof(DStruct) - 255 + l;
  883.    itemlist = NewHandle(DSsize);
  884.  
  885.    movmem(&DStruct, *itemlist, (short) DSsize);
  886.  
  887.    arrowcursor();
  888.    theBox = NewDialog(&dStorage, &boundry, "Debug Text",
  889.                       visible, dBoxProc, behind, goAway, 0L, itemlist);
  890.     ctrwindow(theBox);
  891.     ShowWindow(theBox);
  892.  
  893.    /* highlight the default item */
  894.    framedflt(theBox);
  895.  
  896.    ModalDialog(filterProc, &dummy);
  897.  
  898.    DisposDialog(theBox);
  899. }
  900.  
  901. srvdlg(flag)
  902. char flag;
  903. {
  904. static DialogRecord dlgrec;
  905. static DialogPtr dlgptr;
  906. DialogPeek dStorage;
  907. WindowPtr behind;
  908.  
  909. switch (flag) {
  910.     case 0: dStorage = &dlgrec;
  911.             behind = (WindowPtr)-1;
  912.             dlgptr = GetNewDialog(259, dStorage, behind);
  913.             ctrwindow(dlgptr);
  914.             ShowWindow(dlgptr);
  915.             DrawDialog(dlgptr);
  916.             return;
  917.     default:
  918.             DisposDialog(dlgptr);
  919.             return;
  920.     }
  921. }
  922.  
  923. note_err(code)
  924. short code;
  925. {
  926. pascal unsigned short DlgFilter();
  927. unsigned short (*filterProc) ();
  928. Handle errtext;
  929. static char nullstr[1] = {0};
  930.  
  931. if (apiopen) {
  932.     if (apiopenreq.noalert) return;
  933.     }
  934.  
  935. errtext = GetResource('STR ', code);
  936. if (errtext == 0) return;
  937.  
  938. if (mf_bgrnd && notifyavail) {
  939.     if (notifymsg(*errtext) == noErr) return;
  940.     }
  941.  
  942. ptoc(*errtext);
  943. ParamText(*errtext, nullstr, nullstr, nullstr);
  944. ctop(*errtext);
  945.  
  946. filterProc = DlgFilter;
  947. arrowcursor();
  948. if (code == mapalrt) {
  949.     NoteAlert(278, filterProc);        /* appears only once */
  950.     }
  951. else {
  952.     NoteAlert(281, filterProc);        /* appears always */
  953.     }
  954. ParamText(nullstr, nullstr, nullstr, nullstr);
  955. }
  956.  
  957. stoperr(code)
  958. short code;
  959. {
  960. pascal unsigned short DlgFilter();
  961. unsigned short (*filterProc) ();
  962. Handle errtext;
  963. static char nullstr[1] = {0};
  964.  
  965. if (apiopen) {
  966.     if (apiopenreq.noalert) return;
  967.     }
  968.  
  969. errtext = GetResource('STR ', code);
  970. if (errtext == 0) return;
  971.  
  972. if (mf_bgrnd && notifyavail) {
  973.     if (notifymsg(*errtext) == noErr) return;
  974.     }
  975.  
  976. ptoc(*errtext);
  977. ParamText(*errtext, nullstr, nullstr, nullstr);
  978. ctop(*errtext);
  979.  
  980. filterProc = DlgFilter;
  981. arrowcursor();
  982. StopAlert(264, filterProc);
  983.  
  984. ParamText(nullstr, nullstr, nullstr, nullstr);
  985. }
  986.  
  987. stopterr(text)
  988. unsigned char *text;
  989. {
  990. pascal unsigned short DlgFilter();
  991. unsigned short (*filterProc) ();
  992. static char nullstr[1] = {0};
  993. OSErr rc;
  994.  
  995. if (apiopen) {
  996.     if (apiopenreq.noalert) return;
  997.     }
  998.  
  999. if (mf_bgrnd && notifyavail) {
  1000.     ctop(text);
  1001.     rc = notifymsg(text);
  1002.     ptoc(text);
  1003.     if (rc == noErr) return;
  1004.     }
  1005.  
  1006. ParamText(text, nullstr, nullstr, nullstr);
  1007.  
  1008. filterProc = DlgFilter;
  1009. arrowcursor();
  1010. StopAlert(264, filterProc);
  1011.  
  1012. ParamText(nullstr, nullstr, nullstr, nullstr);
  1013. }
  1014.  
  1015. OSErr notifymsg(msg)
  1016. unsigned char *msg;        /* Pascal string */
  1017. {
  1018. short i, n;
  1019. nmrmessage *nmp;
  1020. OSErr rc;
  1021. extern nmproc();
  1022.  
  1023. n = -1;
  1024. for (i=0; i < NMRNUM; i++) {
  1025.     if (myNMR[i]->qelem.nmRefCon == 0) {
  1026.         n = i;
  1027.         break;
  1028.         }
  1029.     }
  1030. if (n == -1) return(1);
  1031. nmp = myNMR[n];
  1032. /* copy message text to message structure */
  1033. memcpy(nmp->msg, "\ptn3270: ", 9);
  1034. i = msg[0];
  1035. if (i > 247) i = 247;
  1036. memcpy(nmp->msg+9, msg+1, i);
  1037. nmp->msg[0] += i;
  1038.  
  1039. /* define notification manager request */
  1040. memset(&nmp->qelem, 0, sizeof(NMRec));
  1041. nmp->qelem.qType = nmType;
  1042. nmp->qelem.nmSound = (Handle)-1;
  1043. nmp->qelem.nmStr = nmp->msg;
  1044. nmp->qelem.nmResp = nmproc;        /* calls nmend */
  1045. nmp->qelem.nmRefCon = GetA5();
  1046. rc = nminstall(&nmp->qelem);
  1047. if (rc != noErr) nmp->qelem.nmRefCon = 0;
  1048. return(rc);
  1049. }
  1050.  
  1051. nmend(nmReqPtr)
  1052. NMRecPtr nmReqPtr;
  1053. {
  1054. nmremove(nmReqPtr);            /* dequeue request */
  1055. nmReqPtr->nmRefCon = 0;        /* mark as available */
  1056. }
  1057.  
  1058. pascal unsigned short  DlgFilter(dlg, eventptr, itemptr)
  1059. DialogPtr dlg;
  1060. EventRecord * eventptr;
  1061. short * itemptr;
  1062. {
  1063. char i;
  1064.  
  1065. if ((!serflg) && netconn) getreq();
  1066. if (tcpinitok) myStask();
  1067.  
  1068. switch(eventptr->what) {
  1069.     case mouseDown:
  1070.         mousehit = eventptr->where;
  1071.         return(0);
  1072.     case keyDown:
  1073.         i = (eventptr->message & 0x7f);    /* ascii code */
  1074.         if ((i == 0x03) || (i == 0x0d)) {
  1075.             (*itemptr) = 1;
  1076.             return(-1);
  1077.             }
  1078.     default:
  1079.         return(0);
  1080.     }
  1081. }
  1082.  
  1083. pascal unsigned short  fmtDlgFilter(dlg, eventptr, itemptr)
  1084. DialogPtr dlg;
  1085. EventRecord * eventptr;
  1086. short * itemptr;
  1087. {
  1088. short i;
  1089. GrafPtr gp;
  1090. Point mouseLoc;
  1091. short gtype;
  1092. Handle gitem;
  1093. Rect gbox, toprect, bottomrect;
  1094.  
  1095. if ((!serflg) && netconn) getreq();
  1096. if (tcpinitok) myStask();
  1097.  
  1098. switch(eventptr->what) {
  1099.     case mouseDown:
  1100.     case mouseUp:
  1101.         GetPort(&gp);
  1102.         SetPort(dlg);
  1103.         mouseLoc = eventptr->where;
  1104.         GlobalToLocal(&mouseLoc);
  1105.         SetPort(gp);
  1106.         GetDItem(dlg, 19, >ype, &gitem, &gbox);
  1107.         if (PtInRect(&mouseLoc, &gbox)) {
  1108.             if ((eventptr->what) == mouseUp) {
  1109.                 (*itemptr) = 19;
  1110.                 return(-1);
  1111.                 }
  1112.             toprect = bottomrect = gbox;
  1113.             toprect.bottom = bottomrect.top = 
  1114.                 (gbox.top + gbox.bottom) / 2;
  1115.             GetDItem(dlg, 18, >ype, &gitem, &gbox);
  1116.             arrowinc(dlg, 18, gitem, &toprect, &bottomrect, 24, fmtmaxrows);
  1117.             (*itemptr) = 17;
  1118.             return(-1);
  1119.             }
  1120.         GetDItem(dlg, 22, >ype, &gitem, &gbox);
  1121.         if (PtInRect(&mouseLoc, &gbox)) {
  1122.             if ((eventptr->what) == mouseUp) {
  1123.                 (*itemptr) = 22;
  1124.                 return(-1);
  1125.                 }
  1126.             toprect = bottomrect = gbox;
  1127.             toprect.bottom = bottomrect.top = 
  1128.                 (gbox.top + gbox.bottom) / 2;
  1129.             GetDItem(dlg, 21, >ype, &gitem, &gbox);
  1130.             arrowinc(dlg, 21, gitem, &toprect, &bottomrect, 80, fmtmaxcols);
  1131.             (*itemptr) = 20;
  1132.             return(-1);
  1133.             }
  1134.         return(0);
  1135.     case keyDown:
  1136.         i = (eventptr->message & 0x7f);    /* ascii code */
  1137.         if ((i == 0x03) || (i == 0x0d)) {
  1138.             (*itemptr) = 1;
  1139.             return(-1);
  1140.             }
  1141.     default:
  1142.         return(0);
  1143.     }
  1144. }
  1145.  
  1146. arrowinc(dlg, item, gitem, increct, decrect, min, max)
  1147. DialogPeek dlg;
  1148. short item;
  1149. Handle gitem;
  1150. Rect *increct, *decrect;
  1151. short min, max;
  1152. {
  1153. char result[256];
  1154. register short num;
  1155. static unsigned long * Ticks = (unsigned long *)0x16a;
  1156. unsigned long ticklim;
  1157. GrafPtr gp;
  1158. Point mouseLoc;
  1159.  
  1160. /* get initial value of item, and make valid if necessary */
  1161. GetIText(gitem, result);
  1162. num = atoi(result);
  1163. if (num < min) num = min;
  1164. if (num > max) num = max;
  1165. sprintf(result, "%d", num);
  1166. SetIText(gitem, result);
  1167. if (item == (dlg->editField)+1) {
  1168.     SelIText(dlg, item, 0, 32767);
  1169.     }
  1170.  
  1171. /* change value while mouse is down and in rectangle */
  1172. ticklim = (*Ticks);
  1173. while (StillDown()) {
  1174.     if ((*Ticks) >= ticklim) {
  1175.         ticklim = (*Ticks) + 7;
  1176.         GetPort(&gp);
  1177.         SetPort(dlg);
  1178.         GetMouse(&mouseLoc);
  1179.         SetPort(gp);
  1180.         if (PtInRect(&mouseLoc, increct)) {
  1181.             if (num == max) continue;
  1182.             num++;
  1183.             }
  1184.         else if (PtInRect(&mouseLoc, decrect)) {
  1185.             if (num == min) continue;
  1186.             num--;
  1187.             }
  1188.         else continue;
  1189.         sprintf(result, "%d", num);
  1190.         SetIText(gitem, result);
  1191.         if (item == (dlg->editField)+1) {
  1192.             SelIText(dlg, item, 0, 32767);
  1193.             }
  1194.         }
  1195.     }
  1196. }
  1197.  
  1198. pascal unsigned short  ListDlgFilter(dlg, eventptr, itemptr)
  1199. DialogPtr dlg;
  1200. EventRecord * eventptr;
  1201. short * itemptr;
  1202. {
  1203. char i;
  1204. Rect itemRect;
  1205. short itemType;
  1206. Handle itemHandle;
  1207. Point where;
  1208. ListHandle list;
  1209. GrafPtr gp;
  1210.  
  1211. if ((!serflg) && netconn) getreq();
  1212. if (tcpinitok) myStask();
  1213.  
  1214.  
  1215. switch(eventptr->what) {
  1216.     case mouseDown:
  1217.         GetPort(&gp);
  1218.         SetPort(dlg);
  1219.         GetDItem(dlg, 14, &itemType, &itemHandle, &itemRect);
  1220.         where = eventptr->where;
  1221.         GlobalToLocal(&where);
  1222.         if (PtInRect(&where, &itemRect)) {
  1223.             *itemptr = 14;
  1224.             itemRect.right -= 15;
  1225.             if (PtInRect(&where, &itemRect)) {
  1226.                 *itemptr = 15;
  1227.                 }
  1228.             list = (ListHandle)((DialogPeek)dlg)->window.refCon;
  1229.             LClick(&where, eventptr->modifiers, list);
  1230.             SetPort(gp);
  1231.             return(-1);
  1232.             }
  1233.         else {
  1234.             SetPort(gp);
  1235.             return(0);
  1236.             }
  1237.         break;
  1238.     case keyDown:
  1239.         i = (eventptr->message & 0x7f);    /* ascii code */
  1240.         if ((i == 0x03) || (i == 0x0d)) {
  1241.             (*itemptr) = 1;
  1242.             return(-1);
  1243.             }
  1244.     default:
  1245.         return(0);
  1246.     }
  1247. }
  1248.  
  1249. xfdlg(code, msg1, msg2, msg3, msg4)
  1250. register short code;
  1251. register char * msg1;
  1252. register char * msg2;
  1253. char * msg3;
  1254. char * msg4;
  1255. {
  1256. static DialogRecord dlgrec;
  1257. static char msg1flg;
  1258. DialogPeek dStorage;
  1259. WindowPtr behind;
  1260. GrafPtr temp;
  1261. struct WStateData * wsptr;
  1262. struct WindowRecord * xtemp;
  1263.  
  1264. switch (code) {
  1265.     case 0:    
  1266.             dStorage = &dlgrec;
  1267.             behind = (WindowPtr)-1;
  1268.             xdlgptr = GetNewDialog(267, dStorage, behind);
  1269.             ctrwindow(xdlgptr);
  1270.             ShowWindow(xdlgptr);
  1271.             xtemp = (struct WindowRecord *)xdlgptr;
  1272.             if (xtemp->dataHandle != 0) {
  1273.                 wsptr = (struct WStateData *)*(xtemp->dataHandle);
  1274.                 wsptr->stdState = xdlgptr->portRect;
  1275.                 GetPort(&temp);
  1276.                 SetPort(xdlgptr);
  1277.                 LocalToGlobal(&(wsptr->stdState.top));
  1278.                 LocalToGlobal(&(wsptr->stdState.bottom));
  1279.                 SetPort(temp);
  1280.                 }
  1281.             xdlg = 1;
  1282.             msg1flg = 0;
  1283.             return;
  1284.     case 1:    
  1285.             if (msg1flg == 0) { 
  1286.                 msg1flg = 1;
  1287.                 settext(xdlgptr, 1, msg1);
  1288.                 }
  1289.             settext(xdlgptr, 3, msg2);
  1290.             settext(xdlgptr, 5, msg3);
  1291.             settext(xdlgptr, 7, msg4);
  1292.             xfGrowIcon();
  1293.             return;
  1294.     default:
  1295.             if (xdlg == 0) return;
  1296.             xdlg = 0;
  1297.             DisposDialog(xdlgptr);
  1298.             return;
  1299.     }
  1300. }
  1301.  
  1302. fmtdlg()
  1303. {
  1304. register DialogPtr dlgptr;
  1305. Ptr dStorage;
  1306. WindowPtr behind;
  1307. unsigned short (*filterProc) ();
  1308. pascal unsigned short DlgFilter();
  1309. pascal void arrowproc();
  1310. short itemHit, lasthit;
  1311. short * itemHitPtr;
  1312. short gtype;
  1313. Handle gitem;
  1314. Rect gbox;
  1315. void (*myitem) ();
  1316. short dfltptsize, altptsize;
  1317. short altrows, altcols;
  1318. short custrows, custcols;
  1319. char windmax, changed, customflag, skipflag, savewpos;
  1320. unsigned char result[256], newnum[10];
  1321. short i;
  1322.  
  1323. dStorage = 0;
  1324. behind = (WindowPtr)-1;
  1325. dlgptr = GetNewDialog(269, dStorage, behind);
  1326. ctrwindow(dlgptr);
  1327. filterProc = fmtDlgFilter;
  1328. itemHitPtr = &itemHit;
  1329.  
  1330. /* define routine to draw user items */
  1331. GetDItem(dlgptr, 19, >ype, &gitem, &gbox);
  1332. myitem = arrowproc;
  1333. SetDItem(dlgptr, 19, gtype, myitem, &gbox);
  1334. GetDItem(dlgptr, 22, >ype, &gitem, &gbox);
  1335. myitem = arrowproc;
  1336. SetDItem(dlgptr, 22, gtype, myitem, &gbox);
  1337. arrowcursor();
  1338. ShowWindow(dlgptr);
  1339. /* frame the default selection */
  1340. framedflt(dlgptr);
  1341.  
  1342. /* copy current settings */
  1343. windmax = cs.windmax;
  1344. dfltptsize = cs.dfltptsize;
  1345. altptsize = cs.altptsize;
  1346. altrows = cs.altrows;
  1347. altcols = cs.altcols;
  1348. custrows = cs.custrows;
  1349. custcols = cs.custcols;
  1350. savewpos = cs.savewpos;
  1351.  
  1352. /* adjust settings to be valid */
  1353. adjfmt(&changed, &windmax, &dfltptsize, &altptsize, &altrows, &altcols);
  1354. if (altptsize == 9) {
  1355.     fmtmaxrows = rowmax9;
  1356.     fmtmaxcols = colmax9;
  1357.     }
  1358. else {
  1359.     fmtmaxrows = rowmax12;
  1360.     fmtmaxcols = colmax12;
  1361.     }
  1362. if (custrows < 24) custrows = 24;
  1363. if (custcols < 80) custcols = 80;
  1364. if (custrows > fmtmaxrows) custrows = fmtmaxrows;
  1365. if (custcols > fmtmaxcols) custcols = fmtmaxcols;
  1366. if (((altrows == 24) && (altcols == 80)) ||
  1367.     ((altrows == 32) && (altcols == 80)) ||
  1368.     ((altrows == 43) && (altcols == 80)) ||
  1369.     ((altrows == 27) && (altcols == 132))) {
  1370.     customflag = 0;
  1371.     }
  1372. else {
  1373.     customflag = 1;
  1374.     custrows = altrows;
  1375.     custcols = altcols;
  1376.     }
  1377.  
  1378. /* display initial settings */
  1379. setfmt(dlgptr, 99, dfltptsize, windmax, altptsize, 
  1380.        altrows, altcols, customflag, custrows, custcols, savewpos);
  1381.  
  1382. itemHit = 99;
  1383. lasthit = 99;
  1384. while (1) {
  1385.     ModalDialog(filterProc, itemHitPtr);
  1386.     if (((lasthit == 18) && (itemHit != 18)) || 
  1387.         ((lasthit == 21) && (itemHit != 21)) ||
  1388.         (itemHit == 19) || (itemHit == 22)) {
  1389.         if ((lasthit == 18) || (itemHit == 19)) {
  1390.             GetDItem(dlgptr, 18, >ype, &gitem, &gbox);
  1391.             GetIText(gitem, result);
  1392.             custrows = atoi(result);
  1393.             if (custrows < 24) custrows = 24;
  1394.             if (custrows > fmtmaxrows) custrows = fmtmaxrows;
  1395.             if (customflag) altrows = custrows;
  1396.             }
  1397.         else {
  1398.             GetDItem(dlgptr, 21, >ype, &gitem, &gbox);
  1399.             GetIText(gitem, result);
  1400.             custcols = atoi(result);
  1401.             if (custcols < 80) custcols = 80;
  1402.             if (custcols > fmtmaxcols) custcols = fmtmaxcols;
  1403.             if (customflag) altcols = custcols;
  1404.             }
  1405.         }
  1406.     if (itemHit < 3) break;
  1407.     skipflag = 0;
  1408.     switch (itemHit) {
  1409.         case 3:        dfltptsize = altptsize = 12;
  1410.                     windmax = 0;
  1411.                     altrows = 24;
  1412.                     altcols = 80;
  1413.                     adjfmt(&changed, &windmax, &dfltptsize, 
  1414.                            &altptsize, &altrows, &altcols);
  1415.                     if (altptsize == 9) {
  1416.                         fmtmaxrows = rowmax9;
  1417.                         fmtmaxcols = colmax9;
  1418.                         }
  1419.                     else {
  1420.                         fmtmaxrows = rowmax12;
  1421.                         fmtmaxcols = colmax12;
  1422.                         }
  1423.                     customflag = 0;
  1424.                     custcols = fmtmaxcols;
  1425.                     custrows = fmtmaxrows;
  1426.                     break;
  1427.         case 5:        dfltptsize = 9;
  1428.                     break;
  1429.         case 6:        dfltptsize = 12;
  1430.                     break;
  1431.         case 7:        windmax ^= 1;
  1432.                     break;
  1433.         case 8:        savewpos ^= 1;
  1434.                     break;
  1435.         case 10:    altptsize = 9;
  1436.                     fmtmaxrows = rowmax9;
  1437.                     fmtmaxcols = colmax9;
  1438.                     break;
  1439.         case 11:    altptsize = 12;
  1440.                     fmtmaxrows = rowmax12;
  1441.                     fmtmaxcols = colmax12;
  1442.                     if (custrows > fmtmaxrows) custrows = fmtmaxrows;
  1443.                     if (custcols > fmtmaxcols) custcols = fmtmaxcols;
  1444.                     if (customflag) {
  1445.                         altrows = custrows;
  1446.                         altcols = custcols;
  1447.                         }
  1448.                     else {
  1449.                         if ((altrows > fmtmaxrows) || (altcols > fmtmaxcols)) {
  1450.                             altrows = 24;
  1451.                             altcols = 80;
  1452.                             }
  1453.                         }
  1454.                     break;                    
  1455.         case 12:    altrows = 24;
  1456.                     altcols = 80;
  1457.                     customflag = 0;
  1458.                     break;
  1459.         case 13:    altrows = 32;
  1460.                     altcols = 80;
  1461.                     customflag = 0;
  1462.                     break;
  1463.         case 14:    altrows = 43;
  1464.                     altcols = 80;
  1465.                     customflag = 0;
  1466.                     break;
  1467.         case 15:    altrows = 27;
  1468.                     altcols = 132;
  1469.                     customflag = 0;
  1470.                     break;
  1471.         case 16:                            /* "custom" button and arrows */
  1472.         case 19:
  1473.         case 22:
  1474.                     altrows = custrows;
  1475.                     altcols = custcols;
  1476.                     customflag = 1;
  1477.                     break;
  1478.         case 18:
  1479.         case 21:
  1480.                     altrows = custrows;        /* include selecting "custom" */
  1481.                     altcols = custcols;
  1482.                     customflag = 1;
  1483.                     
  1484.                     GetDItem(dlgptr, itemHit, >ype, &gitem, &gbox);
  1485.                     GetIText(gitem, result);
  1486.                     i = 0;
  1487.                     while (result[i] != 0) {
  1488.                         if ((result[i] != 0x20) && ((result[i] < 0x30) ||
  1489.                             (result[i] > 0x39))) {
  1490.                             SysBeep(1);
  1491.                             break;
  1492.                             }
  1493.                         i++;
  1494.                         }
  1495.                     i = atoi(result) % 1000;
  1496.                     if (i == 0) {
  1497.                         newnum[0] = 0;
  1498.                         }
  1499.                     else {
  1500.                         sprintf(newnum, "%d", i);
  1501.                         }
  1502.                     if (strcmp(result, newnum) != 0) SetIText(gitem, newnum);
  1503.                     break;
  1504.         default:
  1505.                     skipflag = 1;
  1506.                     break;
  1507.         }
  1508.     if (!skipflag) setfmt(dlgptr, itemHit, dfltptsize, windmax, altptsize, 
  1509.                        altrows, altcols, customflag, custrows, custcols, savewpos);
  1510.     lasthit = itemHit;
  1511.     }
  1512. DisposDialog(dlgptr);
  1513. if (itemHit == 1) {
  1514.     cs.windmax = windmax;
  1515.     cs.dfltptsize = dfltptsize;
  1516.     cs.altptsize = altptsize;
  1517.     cs.altrows = altrows;
  1518.     cs.altcols = altcols;
  1519.     cs.custrows = custrows;
  1520.     cs.custcols = custcols;
  1521.     cs.savewpos = savewpos;
  1522.     newwindfmt();    /* make changes now if possible */
  1523.     }
  1524. }
  1525.  
  1526. setfmt(dlgptr, itemHit, dfltptsize, windmax, altptsize, 
  1527.        altrows, altcols, customflag, custrows, custcols, savewpos)
  1528. DialogPtr dlgptr;
  1529. short itemHit, dfltptsize, altptsize, altrows, altcols;
  1530. short custrows, custcols;
  1531. char windmax, customflag, savewpos;
  1532. {
  1533. short crows, ccols;
  1534. short gtype;
  1535. Handle gitem;
  1536. Rect gbox;
  1537. unsigned char result[256], newnum[10];
  1538.  
  1539. if (itemHit == 18) {
  1540.     GetDItem(dlgptr, 18, >ype, &gitem, &gbox);
  1541.     GetIText(gitem, result);
  1542.     crows = atoi(result);
  1543.     }
  1544. else crows = custrows;
  1545. if (itemHit == 21) {
  1546.     GetDItem(dlgptr, 21, >ype, &gitem, &gbox);
  1547.     GetIText(gitem, result);
  1548.     ccols = atoi(result);
  1549.     }
  1550. else ccols = custcols;
  1551. setactive(1, dlgptr,
  1552.     !(customflag && ((crows > fmtmaxrows) || (ccols > fmtmaxcols) ||
  1553.                       (crows < 24) || (ccols < 80))));
  1554. setit(5, dlgptr, dfltptsize == 9);
  1555. setit(6, dlgptr, dfltptsize == 12);
  1556. setactive(6, dlgptr, (rowmax12 >= 24) && (colmax12 >= 80));
  1557. setit(7, dlgptr, windmax);
  1558. setit(8, dlgptr, savewpos);
  1559. setit(10, dlgptr, altptsize == 9);
  1560. setit(11, dlgptr, altptsize == 12);
  1561. setactive(11, dlgptr, (rowmax12 >= 24) && (colmax12 >= 80));
  1562. setit(12, dlgptr, (altrows == 24) && (altcols == 80) && (!customflag));
  1563. setit(13, dlgptr, (altrows == 32) && (altcols == 80) && (!customflag));
  1564. setactive(13, dlgptr, fmtmaxrows >= 32);
  1565. setit(14, dlgptr, (altrows == 43) && (altcols == 80) && (!customflag));
  1566. setactive(14, dlgptr, fmtmaxrows >= 43);
  1567. setit(15, dlgptr, (altrows == 27) && (altcols == 132) && (!customflag));
  1568. setactive(15, dlgptr, (fmtmaxrows >= 27) && (fmtmaxcols >= 132));
  1569. setit(16, dlgptr, customflag);
  1570.  
  1571. if (itemHit != 18) {
  1572.     GetDItem(dlgptr, 18, >ype, &gitem, &gbox);
  1573.     GetIText(gitem, result);
  1574.     sprintf(newnum, "%d", custrows);
  1575.     if (strcmp(result, newnum) != 0) {
  1576.         SetIText(gitem, newnum);
  1577.         }
  1578.     }
  1579.  
  1580. if (itemHit != 21) {
  1581.     GetDItem(dlgptr, 21, >ype, &gitem, &gbox);
  1582.     GetIText(gitem, result);
  1583.     sprintf(newnum, "%d", custcols);
  1584.     if (strcmp(result, newnum) != 0) {
  1585.         SetIText(gitem, newnum);
  1586.         }
  1587.     }
  1588. }
  1589.  
  1590. pascal void arrowproc(dlgwindow, item)
  1591. WindowPtr dlgwindow;
  1592. short item;
  1593. {
  1594. GrafPtr gp;
  1595. Rect myrect;
  1596. short dtype;
  1597. Handle ditem;
  1598. PolyHandle ph;
  1599.  
  1600. GetDItem(dlgwindow, item, &dtype, &ditem, &myrect);
  1601. GetPort(&gp);
  1602. SetPort(dlgwindow);
  1603. FrameRoundRect(&myrect, 8, 8);
  1604.  
  1605. ph = OpenPoly();
  1606. MoveTo(myrect.left+2, myrect.top+5);
  1607. LineTo(myrect.left+5, myrect.top+2);
  1608. LineTo(myrect.left+8, myrect.top+5);
  1609. LineTo(myrect.left+6, myrect.top+5);
  1610. LineTo(myrect.left+6, myrect.top+7);
  1611. LineTo(myrect.left+4, myrect.top+7);
  1612. LineTo(myrect.left+4, myrect.top+5);
  1613. LineTo(myrect.left+2, myrect.top+5);
  1614. ClosePoly();
  1615. FramePoly(ph);
  1616. PaintPoly(ph);
  1617. KillPoly(ph);
  1618.  
  1619. ph = OpenPoly();
  1620. MoveTo(myrect.left+2, myrect.top+12);
  1621. LineTo(myrect.left+5, myrect.top+15);
  1622. LineTo(myrect.left+8, myrect.top+12);
  1623. LineTo(myrect.left+6, myrect.top+12);
  1624. LineTo(myrect.left+6, myrect.top+10);
  1625. LineTo(myrect.left+4, myrect.top+10);
  1626. LineTo(myrect.left+4, myrect.top+12);
  1627. LineTo(myrect.left+2, myrect.top+12);
  1628. ClosePoly();
  1629. FramePoly(ph);
  1630. PaintPoly(ph);
  1631. KillPoly(ph);
  1632.  
  1633. SetPort(gp);
  1634. }
  1635.  
  1636. miscdlg()
  1637. {
  1638. register DialogPtr dlgptr;
  1639. Ptr dStorage;
  1640. WindowPtr behind;
  1641. unsigned short (*filterProc) ();
  1642. pascal unsigned short ListDlgFilter();
  1643. short itemHit;
  1644. short * itemHitPtr;
  1645. short gtype;
  1646. Handle gitem;
  1647. Rect gbox;
  1648. void (*myitem) ();
  1649. short newtime, newblock, newpos;
  1650. GrafPtr gp;
  1651. pascal void misctext();
  1652. pascal void listproc();
  1653. ListHandle list;
  1654. Rect dataBounds;
  1655. Point cellSize, cell;
  1656. short i, sndcount, namelen;
  1657. char loadflag;
  1658. Handle reshandle, reshandle2;
  1659. short resid;
  1660. long restype;
  1661. char resname[256];
  1662. OSErr rc;
  1663. Handle getsndresource();
  1664.  
  1665. dStorage = 0;
  1666. behind = (WindowPtr)-1;
  1667. dlgptr = GetNewDialog(271, dStorage, behind);
  1668. ctrwindow(dlgptr);
  1669. if (newroms) {
  1670.     filterProc = ListDlgFilter;
  1671.     }
  1672. else {
  1673.     filterProc = DlgFilter;
  1674.     }
  1675. itemHitPtr = &itemHit;
  1676. GetPort(&gp);
  1677. SetPort(dlgptr);
  1678.  
  1679. /* define routine to draw user items */
  1680. GetDItem(dlgptr, 13, >ype, &gitem, &gbox);
  1681. myitem = misctext;
  1682. SetDItem(dlgptr, 13, gtype, myitem, &gbox);
  1683.  
  1684. GetDItem(dlgptr, 14, >ype, &gitem, &gbox);
  1685. myitem = listproc;
  1686. SetDItem(dlgptr, 14, gtype, myitem, &gbox);
  1687.  
  1688. if (newroms) {
  1689.     /* make room for scroll bar */
  1690.     gbox.right -= 15;
  1691.  
  1692.     /* create a list */
  1693.     dataBounds.top = dataBounds.left = 0;
  1694.     sndcount = CountResources('snd ');
  1695.     dataBounds.bottom = sndcount + 1;
  1696.     dataBounds.right = 1;
  1697.     cellSize.h = cellSize.v = 0;    /* use defaults */
  1698.     list = LNew(&gbox, &dataBounds, &cellSize, 0, (WindowPtr)dlgptr,
  1699.                 false, false, false, true);
  1700.  
  1701.     /* allow the dialog manager routines to access the list record */
  1702.     ((DialogPeek)dlgptr)->window.refCon = (long)list;
  1703.  
  1704.     /* allow only one selection at a time */
  1705.     (*list)->selFlags = lOnlyOne;
  1706.     }
  1707. else {
  1708.     setactive(13, dlgptr, 0);
  1709.     }
  1710.  
  1711. setit(4, dlgptr, cs.stat_time==1);
  1712. setit(5, dlgptr, cs.stat_time==2);
  1713. setit(6, dlgptr, cs.stat_time==0);
  1714. setit(8, dlgptr, cs.blockcurs==0);
  1715. setit(9, dlgptr, cs.blockcurs==1);
  1716. setit(11, dlgptr, cs.curpos==0);
  1717. setit(12, dlgptr, cs.curpos==1);
  1718.  
  1719. if (newroms) {
  1720.     /* Initialize cell contents */
  1721.     cell.h = cell.v = 0;
  1722.     strcpy(resname, dfltsoundname);
  1723.     namelen = strlen(resname);
  1724.     LSetCell(resname, namelen, &cell, list);
  1725.     if (strcmp(resname, cssndname) == 0) LSetSelect(true, &cell, list);
  1726.     if (sndcount > 0) {
  1727.         for (i=1; i <= sndcount; i++) {
  1728.             cell.v++;
  1729.             loadflag = 0;
  1730.             SetResLoad(false);
  1731.             reshandle = GetIndResource('snd ', i);
  1732.             SetResLoad(true);
  1733.             if (reshandle == 0) {
  1734.                 loadflag = 1;
  1735.                 reshandle = GetIndResource('snd ', i);
  1736.                 }        
  1737.             if (reshandle != 0) {
  1738.                 getsndinfo(reshandle, &resid, &restype, resname);
  1739.                 if (loadflag) ReleaseResource(reshandle);
  1740.                 namelen = strlen(resname);
  1741.                 LSetCell(resname, namelen, &cell, list);
  1742.                 if (strcmp(resname, cssndname) == 0)
  1743.                     LSetSelect(true, &cell, list);
  1744.                 }
  1745.             }
  1746.         }
  1747.     LAutoScroll(list);
  1748.     LDoDraw(true, list);
  1749.     }
  1750.  
  1751. newtime = cs.stat_time;
  1752. newblock = cs.blockcurs;
  1753. newpos = cs.curpos;
  1754. arrowcursor();
  1755. ShowWindow(dlgptr);
  1756. /* frame the default selection */
  1757. framedflt(dlgptr);
  1758.  
  1759. itemHit = 99;
  1760. resname[0] = 0;
  1761. while (itemHit > 2) {
  1762.     ModalDialog(filterProc, itemHitPtr);
  1763.     switch (itemHit) {
  1764.         case 4:
  1765.             newtime = 1;
  1766.             break;
  1767.         case 5:
  1768.             newtime = 2;
  1769.             break;
  1770.         case 6:
  1771.             newtime = 0;
  1772.             break;
  1773.         case 8:
  1774.             newblock = 0;
  1775.             break;
  1776.         case 9:
  1777.             newblock = 1;
  1778.             break;
  1779.         case 11:
  1780.             newpos = 0;
  1781.             break;
  1782.         case 12:
  1783.             newpos = 1;
  1784.             break;
  1785.         case 14:
  1786.         case 15:
  1787.             if (!newroms) {
  1788.                 beep();
  1789.                 break;
  1790.                 }
  1791.             resname[0] = 0;
  1792.             cell.h = 0;
  1793.             for (cell.v=0; cell.v < sndcount+1; cell.v++) {
  1794.                 if (LGetSelect(false, &cell, list)) {
  1795.                     namelen = 255;
  1796.                     LGetCell(resname, &namelen, &cell, list);
  1797.                     resname[namelen] = 0;
  1798.                     break;
  1799.                     }
  1800.                 }
  1801.             if ((strlen(resname) > 0) && (itemHit == 15)) {
  1802.                 if (strcmp(resname, dfltsoundname) == 0) {
  1803.                     SysBeep(3);
  1804.                     }
  1805.                 else {
  1806.                     dlgplaysound(resname);
  1807.                     }
  1808.                 }
  1809.             break;
  1810.         default:
  1811.             break;
  1812.         }
  1813.     if ((itemHit >= 4) && (itemHit <= 12)) {
  1814.         setit(4, dlgptr, newtime==1);
  1815.         setit(5, dlgptr, newtime==2);
  1816.         setit(6, dlgptr, newtime==0);
  1817.         setit(8, dlgptr, newblock==0);
  1818.         setit(9, dlgptr, newblock==1);
  1819.         setit(11, dlgptr, newpos==0);
  1820.         setit(12, dlgptr, newpos==1);
  1821.         }
  1822.     }
  1823. if (newroms) {
  1824.     LDispose(list);
  1825.     }
  1826. SetPort(gp);
  1827. DisposDialog(dlgptr);
  1828. if (itemHit == 1) {
  1829.     if (cs.stat_time != newtime) {
  1830.         cs.stat_time = newtime;
  1831.         if (myWindow != 0) newstat();
  1832.         }
  1833.     if (cs.blockcurs != newblock) {
  1834.         cs.blockcurs = newblock;
  1835.         if (myWindow != 0) newcur();
  1836.         }
  1837.     if (cs.curpos != newpos) {
  1838.         cs.curpos = newpos;
  1839.         if (myWindow != 0) newstat();
  1840.         }
  1841.     if ((strcmp(cssndname, resname) != 0) && (resname[0] != 0)) {
  1842.         if (strcmp(resname, dfltsoundname) == 0) {
  1843.             if (sndactive) {
  1844.                 SndDisposeChannel(scp, true);
  1845.                 sndactive = 0;
  1846.                 }
  1847.             if (sndhandle != 0) DisposHandle(sndhandle);
  1848.             sndhandle = 0;
  1849.             strcpy(cssndname, resname);
  1850.             }
  1851.         else {
  1852.             reshandle = reshandle2 = getsndresource(resname);
  1853.             if (reshandle != 0) {
  1854.                 rc = HandToHand(&reshandle2);
  1855.                 if (rc != noErr) {
  1856.                     ReleaseResource(reshandle);
  1857.                     stoperr(sdmemalrt);
  1858.                     }
  1859.                 else {
  1860.                     getsndinfo(reshandle, &resid, &restype, resname);
  1861.                     ReleaseResource(reshandle);
  1862.                     if (sndactive) {
  1863.                         SndDisposeChannel(scp, true);
  1864.                         sndactive = 0;
  1865.                         }
  1866.                     if (sndhandle != 0) DisposHandle(sndhandle);
  1867.                     sndhandle = reshandle2;
  1868.                     strcpy(cssndname, resname);
  1869.                     }
  1870.                 }
  1871.             }
  1872.         }
  1873.     }
  1874. }
  1875.  
  1876. dlgplaysound(sndname)
  1877. char * sndname;
  1878. {
  1879. Handle temph, temph2, getsndresource();
  1880. OSErr rc;
  1881. SndChannelPtr default_scp;
  1882.  
  1883. temph = temph2 = getsndresource(sndname);
  1884. if (temph == 0) return;
  1885. rc = HandToHand(&temph2);
  1886. ReleaseResource(temph);
  1887. if (rc == noErr) {
  1888.     if (sndactive) {
  1889.         SndDisposeChannel(scp, true);
  1890.         sndactive = 0;
  1891.         }
  1892.     default_scp = 0;
  1893.     rc = SndNewChannel(&default_scp, 0, 0L, 0L);
  1894.     if (rc == noErr) {
  1895.         SndPlay(default_scp, temph2, 0);
  1896.         SndDisposeChannel(default_scp, 0);
  1897.         }
  1898.     DisposHandle(temph2);
  1899.     }
  1900. }
  1901.  
  1902. pascal void listproc(dialog, itemNo)
  1903. DialogPtr dialog;
  1904. short itemNo;
  1905. {
  1906. ListHandle list;
  1907. short itemType;
  1908. Handle itemHandle;
  1909. Rect itemRect;
  1910.  
  1911. GetDItem(dialog, itemNo, &itemType, &itemHandle, &itemRect);
  1912. if (newroms) {
  1913.     list = (ListHandle)((DialogPeek)dialog)->window.refCon;
  1914.     LUpdate(dialog->visRgn, list);
  1915.     }
  1916. InsetRect(&itemRect, -1, -1);
  1917. if (!newroms) PenPat(qd.gray);
  1918. FrameRect(&itemRect);
  1919. if (!newroms) PenPat(qd.black);
  1920. }
  1921.  
  1922. pascal void misctext(wp, inum)
  1923. WindowPtr wp;
  1924. short inum;
  1925. {
  1926. short gtype;
  1927. Handle gitem;
  1928. Rect gbox;
  1929. GrafPort mp;
  1930. GrafPtr gp;
  1931. OSErr dlgnewmap(), rc;
  1932.  
  1933. GetDItem(wp, inum, >ype, &gitem, &gbox);
  1934. rc = dlgnewmap(&mp, &gbox);
  1935. if (rc != 0) return;
  1936. GetPort(&gp);
  1937. SetPort(&mp);
  1938. MoveTo(gbox.left, gbox.top+12);
  1939. switch(inum) {
  1940.     case 13:
  1941.         DrawString("Beep Sound:");
  1942.         break;
  1943.     default:
  1944.         break;
  1945.     }
  1946. if (!newroms) {
  1947.     PenPat(qd.gray);
  1948.     PenMode(patBic);
  1949.     PaintRect(&gbox);
  1950.     }
  1951. SetPort(wp);
  1952. CopyBits(&mp.portBits, &(wp->portBits), &gbox, &gbox, srcCopy, 0L);
  1953. SetPort(gp);
  1954. ClosePort(&mp);
  1955. DisposPtr(dlgmapptr);
  1956. }
  1957.  
  1958. OSErr dlgnewmap(wp, box)
  1959. GrafPtr wp;
  1960. Rect * box;
  1961. {
  1962. BitMap dlgWriteMap;
  1963. Size mapsize;
  1964. Ptr myNewPtr();
  1965. GrafPtr gp;
  1966.  
  1967. dlgWriteMap.bounds = *box;
  1968. dlgWriteMap.rowBytes =
  1969.     (dlgWriteMap.bounds.right - dlgWriteMap.bounds.left + 7) >> 3;
  1970. if (dlgWriteMap.rowBytes%2) dlgWriteMap.rowBytes++;
  1971. mapsize = dlgWriteMap.bounds.bottom - dlgWriteMap.bounds.top;
  1972. mapsize = mapsize * dlgWriteMap.rowBytes;
  1973. dlgmapptr = myNewPtr(mapsize);
  1974. if (dlgmapptr == 0L) return(4);
  1975. dlgWriteMap.baseAddr = dlgmapptr;
  1976. wp->portRect = dlgWriteMap.bounds;
  1977. GetPort(&gp);
  1978. OpenPort(wp);
  1979. SetPortBits(&dlgWriteMap);
  1980. EraseRgn(wp->visRgn);
  1981. SetPort(gp);
  1982. }
  1983.  
  1984. getsndinfo(theResource, theID, theType, name)
  1985. Handle theResource;
  1986. short *theID;
  1987. ResType *theType;
  1988. unsigned char *name;
  1989. {
  1990. short i, namelength;
  1991.  
  1992. GetResInfo(theResource, theID, theType, name);
  1993. namelength = strlen(name);
  1994. if (namelength > 0) {
  1995.     for (i=0; i < namelength; i++) {
  1996.         if (!isspace(name[i])) return;
  1997.         }
  1998.     }
  1999. /* if we get here, the name is null, or all white space */
  2000. /* generate a pseudo-name for the user and "getsndresource" */
  2001. sprintf(name, "(unnamed) #%d", *theID);
  2002. }
  2003.  
  2004. Handle getsndresource(name)
  2005. unsigned char *name;
  2006. {
  2007. int resnum;
  2008.  
  2009. if (strlen(name) > 11) {
  2010.     if (strncmp(name, "(unnamed) #", 11) == 0) {
  2011.         if (1 == sscanf(name+11, "%d", &resnum)) {
  2012.             return(GetResource('snd ', resnum));
  2013.             }
  2014.         }
  2015.     }
  2016. return(GetNamedResource('snd ', name));
  2017. }
  2018.  
  2019. void crsetdlg()
  2020. {
  2021. DialogPtr dlgptr;
  2022. Ptr dStorage;
  2023. WindowPtr behind;
  2024. unsigned short (*filterProc) ();
  2025. short * itemHitPtr;
  2026. short itemHit, oldHit;
  2027. short gtype;
  2028. Handle gitem;
  2029. Rect gbox;
  2030. union {
  2031.     OSType type;
  2032.     unsigned char name[4];
  2033.     } cr;
  2034. unsigned char crstr[5];
  2035. unsigned char instr[256];
  2036. char showok;
  2037. OSErr rc;
  2038.  
  2039. dStorage = 0;
  2040. behind = (WindowPtr)-1;
  2041. dlgptr = GetNewDialog(283, dStorage, behind);
  2042. ctrwindow(dlgptr);
  2043.  
  2044. /* copy current value of creator */
  2045. cr.type = cs.text_creator;
  2046. memcpy(crstr+1, cr.name, 4);
  2047. crstr[0] = 4;
  2048.  
  2049. /* define creator text */
  2050. GetDItem(dlgptr, 5, >ype, &gitem, &gbox);
  2051. p2cstr(crstr);
  2052. SetIText(gitem, crstr);
  2053. c2pstr(crstr);
  2054. SelIText(dlgptr, 5, 0, 32767);
  2055.  
  2056. /* handle file creator dialog */
  2057. filterProc = DlgFilter;
  2058. itemHitPtr = &itemHit;
  2059.  
  2060. ShowWindow(dlgptr);
  2061.  
  2062. /* frame the default selection */
  2063. framedflt(dlgptr);
  2064.  
  2065. oldHit = 0;
  2066. showok = 1;
  2067. while (1) {
  2068.     /* ModalDialog((ModalFilterProcPtr)filterProc, itemHitPtr); */
  2069.     ModalDialog(filterProc, itemHitPtr);
  2070.     if ((oldHit > 0) && (oldHit != itemHit))
  2071.         switch(oldHit) {
  2072.         case 5:
  2073.                 GetDItem(dlgptr, 5, >ype, &gitem, &gbox);
  2074.                 GetIText(gitem, instr);
  2075.                 c2pstr(instr);
  2076.                 memcpy(crstr, instr, 5);
  2077.                 if (crstr[0] > 4) crstr[0] = 4;
  2078.                 while (crstr[0] < 4) {
  2079.                     crstr[crstr[0]+1] = ' ';
  2080.                     crstr[0]++;
  2081.                     }
  2082.                 break;
  2083.         default:
  2084.                 break;
  2085.         }
  2086.     oldHit = itemHit;
  2087.     switch(itemHit) {
  2088.         case 1:                                    /* OK */
  2089.                 memcpy(cr.name, crstr+1, 4);
  2090.                 cs.text_creator = cr.type;
  2091.                 break;
  2092.         case 2:                                    /* get from app. */
  2093.                 rc = getapcr(&cr.type);
  2094.                 if (rc != noErr) {
  2095.                     framedflt(dlgptr);
  2096.                     break;
  2097.                     }
  2098.                 if (!showok) {
  2099.                     showok = 1;
  2100.                     GetDItem(dlgptr, 1, >ype, &gitem, &gbox);
  2101.                     HiliteControl((ControlHandle)gitem, 0);
  2102.                     }
  2103.                 framedflt(dlgptr);
  2104.                 memcpy(crstr+1, cr.name, 4);
  2105.                 crstr[0] = 4;
  2106.                 GetDItem(dlgptr, 5, >ype, &gitem, &gbox);
  2107.                 p2cstr(crstr);
  2108.                 SetIText(gitem, crstr);
  2109.                 c2pstr(crstr);
  2110.                 SelIText(dlgptr, 5, 0, 32767);
  2111.                 break;
  2112.         case 5:
  2113.                 GetDItem(dlgptr, 5, >ype, &gitem, &gbox);
  2114.                 GetIText(gitem, instr);
  2115.                 c2pstr(instr);
  2116.                 if ((instr[0] < 1) || (instr[0] > 4)) {
  2117.                     if (showok) {
  2118.                         showok = 0;
  2119.                         GetDItem(dlgptr, 1, >ype, &gitem, &gbox);
  2120.                         HiliteControl((ControlHandle)gitem, 255);
  2121.                         framedflt(dlgptr);
  2122.                         }
  2123.                     }
  2124.                 else {
  2125.                     if (!showok) {
  2126.                         showok = 1;
  2127.                         GetDItem(dlgptr, 1, >ype, &gitem, &gbox);
  2128.                         HiliteControl((ControlHandle)gitem, 0);
  2129.                         framedflt(dlgptr);
  2130.                         }
  2131.                     }
  2132.                 break;
  2133.         default: break;
  2134.         }
  2135.     if ((itemHit == 1) || (itemHit == 3)) break;
  2136.     }
  2137.  
  2138. /* dispose of dialog and return */
  2139. DisposDialog(dlgptr);
  2140. }
  2141.  
  2142. void psdlg()
  2143. {
  2144. DialogPtr dlgptr;
  2145. Ptr dStorage;
  2146. WindowPtr behind;
  2147. unsigned short (*filterProc) ();
  2148. short * itemHitPtr;
  2149. short itemHit;
  2150. short gtype;
  2151. Handle gitem;
  2152. Rect gbox;
  2153. OSErr rc;
  2154. char dlgps;
  2155.  
  2156. dStorage = 0;
  2157. behind = (WindowPtr)-1;
  2158. dlgptr = GetNewDialog(284, dStorage, behind);
  2159. ctrwindow(dlgptr);
  2160.  
  2161. /* copy current value of flag and display it */
  2162. dlgps = cs.simps;
  2163. GetDItem(dlgptr, 3, >ype, &gitem, &gbox);
  2164. SetCtlValue(gitem, dlgps);
  2165.  
  2166. /* handle PS simulation dialog */
  2167. filterProc = DlgFilter;
  2168. itemHitPtr = &itemHit;
  2169.  
  2170. ShowWindow(dlgptr);
  2171.  
  2172. /* frame the default selection */
  2173. framedflt(dlgptr);
  2174.  
  2175. while (1) {
  2176.     /* ModalDialog((ModalFilterProcPtr)filterProc, itemHitPtr); */
  2177.     ModalDialog(filterProc, itemHitPtr);
  2178.     switch(itemHit) {
  2179.         case 1:                                    /* OK */
  2180.                 cs.simps = dlgps; 
  2181.                 break;
  2182.         case 2:                                    /* Cancel */
  2183.                 break;
  2184.         case 3:                                    /* Check Box */
  2185.         case 4:
  2186.                 dlgps ^= 1;
  2187.                 GetDItem(dlgptr, 3, >ype, &gitem, &gbox);
  2188.                 SetCtlValue(gitem, dlgps);
  2189.                 break;
  2190.         default: break;
  2191.         }
  2192.     if (itemHit < 3) break;
  2193.     }
  2194.  
  2195. /* dispose of dialog and return */
  2196. DisposDialog(dlgptr);
  2197. }
  2198.  
  2199. OSErr getapcr(cr)
  2200. OSType *cr;
  2201. {
  2202. Point where;
  2203. /* FileFilterProcPtr fileFilter; */
  2204. ProcPtr fileFilter;
  2205. short numTypes;
  2206. SFTypeList typeList;
  2207. /* DlgHookProcPtr dlgHook; */
  2208. ProcPtr dlgHook;
  2209. SFReply reply;
  2210. FileParam fblk;
  2211. FileParam * _fblk;
  2212. OSErr rc;
  2213.  
  2214. where = sfgpoint;
  2215. fileFilter = 0;
  2216. dlgHook = 0;
  2217. numTypes = 1;
  2218. typeList[0] = 'APPL';
  2219. SFGetFile(&where ,"",fileFilter,numTypes,
  2220.     typeList,dlgHook,&reply);
  2221. if (reply.good == 0) return(1);
  2222.  
  2223. _fblk = &fblk;
  2224. fblk.ioCompletion = 0;
  2225. fblk.ioNamePtr = (StringPtr)&reply.fName;
  2226. fblk.ioVRefNum = reply.vRefNum;
  2227. fblk.ioFVersNum = 0;
  2228. fblk.ioFDirIndex = 0;
  2229. rc = PBGetFInfo((ParmBlkPtr)_fblk, 0);
  2230. if (rc != noErr) return(rc);
  2231. (*cr) = fblk.ioFlFndrInfo.fdCreator;
  2232. return(noErr);
  2233. }
  2234.  
  2235. setit(item, dlgptr, code)
  2236. register short item, code;
  2237. register DialogPtr dlgptr;
  2238. {
  2239. short gtype;
  2240. Handle gitem;
  2241. Rect gbox;
  2242.  
  2243. GetDItem(dlgptr, item, >ype, &gitem, &gbox);
  2244. SetCtlValue(gitem, code);
  2245. }
  2246.  
  2247. setactive(item, dlgptr, flag)
  2248. register short item;
  2249. register DialogPtr dlgptr;
  2250. register char flag;
  2251. {
  2252. short gtype;
  2253. Handle gitem;
  2254. Rect gbox;
  2255.  
  2256. GetDItem(dlgptr, item, >ype, &gitem, &gbox);
  2257. if (flag) {
  2258.     HiliteControl(gitem, 0);
  2259.     }
  2260. else {
  2261.     HiliteControl(gitem, 255);
  2262.     }
  2263. if (item == 1) framedflt(dlgptr);
  2264. }
  2265.  
  2266. short wants_to_quit()
  2267.             /* if a session is in progress, verify user wants to quit */
  2268. {
  2269. pascal unsigned short DlgFilter();
  2270. unsigned short (*filterProc) ();
  2271. short item;
  2272. static char nullstr[1] = {0};
  2273.  
  2274.                     /* return TRUE if no connection established */
  2275. if (serflg) {
  2276.     if (connflg) return(1);            /* no serial 3270 connection */
  2277.     }
  2278. else if (tcpflg) {
  2279.     if (!tcp_session()) return(1);    /* no TCP/IP 3270 or line mode connection */
  2280.     }
  2281. else if (!netconn) return(1);        /* no AppleTalk connection */
  2282.  
  2283. filterProc = DlgFilter;
  2284. arrowcursor();
  2285. ParamText(sessionhost, nullstr, nullstr, nullstr);
  2286. item = CautionAlert(279, filterProc);
  2287. ParamText(nullstr, nullstr, nullstr, nullstr);
  2288. if (item == 1) return(0);        /* resume */
  2289. else return(1);                    /* end session */
  2290. }
  2291.  
  2292. dFullAlt(kShort)
  2293. register short kShort;
  2294. {
  2295. pascal unsigned short DlgFilter();
  2296. unsigned short (*filterProc) ();
  2297. char buf[10];
  2298.  
  2299. sprintf(buf, "%d", kShort);
  2300.  
  2301. ParamText(macFName+1, buf, macVName+1, "");
  2302. filterProc = DlgFilter;
  2303. arrowcursor();
  2304. StopAlert(265, filterProc);
  2305. }
  2306.  
  2307. settext(dlgptr, item, text)
  2308. register DialogPtr dlgptr;
  2309. register short item;
  2310. register char *text;
  2311. {
  2312.     short gtype;
  2313.     Handle gitem;
  2314.     Rect gbox;
  2315.  
  2316.     GetDItem(dlgptr, item, >ype, &gitem, &gbox);
  2317.     SetIText(gitem, text);
  2318. }
  2319.  
  2320. ctrwindow(wp)
  2321. GrafPtr wp;
  2322. {
  2323. short scrhsize, scrvsize;
  2324. short whsize, wvsize;
  2325.  
  2326. scrhsize = qd.screenBits.bounds.right - qd.screenBits.bounds.left;
  2327. scrvsize = qd.screenBits.bounds.bottom - qd.screenBits.bounds.top;
  2328. whsize = wp->portRect.right-wp->portRect.left;
  2329. wvsize = wp->portRect.bottom - wp->portRect.top;
  2330. MoveWindow(wp, (scrhsize-whsize)/2, (scrvsize-wvsize)/3, 0);
  2331. }
  2332.  
  2333. ctralrt(a)
  2334. short a;        /* alert number */
  2335. {
  2336. Handle reshnd;
  2337. struct Rect * rptr;
  2338. short scrhsize, scrvsize;
  2339. short ahsize, avsize;
  2340.  
  2341. CouldAlert(a);        /* read alert into memory and make unpurgeable */
  2342. reshnd = GetResource('ALRT', a);
  2343. if (reshnd == 0) return;
  2344. rptr = (struct Rect *)*reshnd;
  2345. scrhsize = qd.screenBits.bounds.right - qd.screenBits.bounds.left;
  2346. scrvsize = qd.screenBits.bounds.bottom - qd.screenBits.bounds.top;
  2347. ahsize = rptr->right - rptr->left;
  2348. avsize = rptr->bottom - rptr->top;
  2349. rptr->top = (scrvsize-avsize)/3;
  2350. rptr->left = (scrhsize-ahsize)/2;
  2351. rptr->bottom = rptr->top + avsize;
  2352. rptr->right = rptr->left + ahsize;
  2353. }
  2354.  
  2355. framedflt(dlgptr)
  2356. DialogPtr dlgptr;
  2357. {
  2358. short gtype;
  2359. Handle gitem;
  2360. Rect gbox;
  2361. GrafPtr gp;
  2362.  
  2363. GetDItem(dlgptr, 1, >ype, &gitem, &gbox);
  2364. GetPort(&gp);
  2365. SetPort(dlgptr);
  2366. OutlineButton(gitem);
  2367. SetPort(gp);
  2368. }
  2369.  
  2370. OutlineButton(button)
  2371. ControlHandle button;
  2372. {
  2373. /* This routine provided by Macintosh DTS: */
  2374.  
  2375. /*    Given any control handle, this will draw an outline around it.  This is
  2376.     used for the default button of a window.  The extra nice feature here is
  2377.     that I'll erase the outline for buttons that are inactive.  Seems like
  2378.     there should be a Toolbox call for getting a control's hilite state.
  2379.     Since there isn't, I have to look into the control record myself.    This
  2380.     should be called for update and activate events.
  2381.  
  2382.     The method for determining the oval diameters for the roundrect is a
  2383.     little different than that recommended by Inside Mac.    IM I-407 suggests
  2384.     that you use a hardcoded (16,16) for the diameters. However, this only
  2385.     looks good for small roundrects. For larger ones, the outline doesn't
  2386.     follow the inner roundrect because the CDEF for simply buttons doesn't
  2387.     use (16,16). Instead, it uses half the height of the button as the
  2388.     diameter. By using this formula, too, our outlines look better.            */
  2389.  
  2390. /*    WARNING: This will set the current port to the control's window.        */
  2391.  
  2392. Rect theRect;
  2393. PenState curPen;
  2394. short buttonOval;
  2395.         
  2396. if (button != 0) {
  2397.     /* SetPort((*button)->contrlOwner); */ /* done by caller */
  2398.     GetPenState(&curPen);
  2399.     PenNormal();
  2400.     theRect = (*button)->contrlRect;
  2401.     InsetRect(&theRect, kButtonFrameInset, kButtonFrameInset);
  2402.     buttonOval = (theRect.bottom - theRect.top) / 2;
  2403.     if ((*button)->contrlHilite == 0) {
  2404.         PenPat(qd.black);
  2405.         }
  2406.     else {
  2407.         PenPat(qd.gray);
  2408.         }
  2409.     PenSize(kButtonFrameSize, kButtonFrameSize);
  2410.     FrameRoundRect(&theRect, buttonOval, buttonOval);
  2411.     SetPenState(&curPen);
  2412.     }
  2413. }
  2414.  
  2415. arrowcursor()
  2416. {
  2417. if (!dfltcurs) {
  2418.     dfltcurs = 1;
  2419.     SetCursor(&qd.arrow);
  2420.     }
  2421. }